const Promise = require('bluebird')
// // this will be counted as if the iterable passed is empty, so it gets fulfilled
// var p = Promise.all([1,2,3]);
// // this will be counted as if the iterable passed contains only the resolved promise with value "444", so it gets fulfilled
// var p2 = Promise.all([1,2,3, Promise.resolve(444)]);
// // this will be counted as if the iterable passed contains only the rejected promise with value "555", so it gets rejected
// var p3 = Promise.all([1,2,3, Promise.reject(555)]);

// // using setTimeout we can execute code after the stack is empty
// setTimeout(function(){
//     console.log(p);
//     console.log(p2);
//     console.log(p3);
// });

// // logs
// // Promise { <state>: "fulfilled", <value>: Array[3] }
// // Promise { <state>: "fulfilled", <value>: Array[4] }
// // Promise { <state>: "rejected", <reason>: 555 }

// var resolvedPromisesArray = [Promise.resolve(33), Promise.resolve(44)];

// var p = Promise.all(resolvedPromisesArray);
// // immediately logging the value of p
// console.log(p);

// var mixedPromisesArray = [Promise.resolve(33), Promise.reject(44)];
// var p = Promise.all(mixedPromisesArray);
// console.log(p);
// setTimeout(function(){
//     console.log('the stack is now empty');
//     console.log(p);
// });


// var p = Promise.all([]); // will be immediately resolved
// var p2 = Promise.all([1337, "hi"]); // non-promise values will be ignored, but the evaluation will be done asynchronously
// console.log('p=' + p);
// console.log('p2=' + p2);
// setTimeout(function(){
//     console.log('the stack is now empty');
//     console.log(p2);
// });

const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'foo');
});

Promise.all([promise1, promise3, promise2]).then((values) => {
  console.log(values);
});